/**
 * @param {number[]} citations
 * @return {number}
 */
var hIndex = function (citations) {
  let len = citations.length
  let l = 0, r = len - 1, res = 0
  while (l <= r) {
    let mid = Math.floor((l + r) / 2)
    if (citations[mid] <= len - mid) {
      res = len - mid
      l = mid + 1
    } else if (citations[mid] > len - mid) {
      l = mid + 1
    }
  }
  return res
}
// console.log(hIndex([0]))
// console.log(hIndex([0, 1, 3, 5, 6]))
// console.log(hIndex([0, 1]))
// console.log(hIndex([100]))
console.log(hIndex([1, 1, 2, 3, 4, 5, 7]))